import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hsh/utils/file_download_utils.dart';

void main() {
  group('FileDownloadUtils Tests', () {
    setUpAll(() {
      // 设置测试环境的方法通道
      TestWidgetsFlutterBinding.ensureInitialized();
    });

    test('should validate asset path exists', () async {
      // 测试assets文件是否存在
      const String assetPath = 'assets/json/dzswsbb.pdf';
      
      try {
        // 尝试加载assets文件
        ByteData data = await rootBundle.load(assetPath);
        expect(data.lengthInBytes, greaterThan(0));
        print('PDF文件大小: ${data.lengthInBytes} bytes');
      } catch (e) {
        fail('无法加载PDF文件: $e');
      }
    });

    test('should generate correct file name with timestamp', () {
      // 测试文件名生成逻辑
      const String originalFileName = '个人所得税申报表.pdf';
      final String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
      
      // 模拟文件名冲突时的处理
      final String expectedPattern = RegExp(r'个人所得税申报表_\d+\.pdf').pattern;
      final String generatedName = '个人所得税申报表_$timestamp.pdf';
      
      expect(RegExp(expectedPattern).hasMatch(generatedName), isTrue);
    });
  });
}